package com.lxu;

/**
 * 多线程场景下，content的值可能会在线程中错乱
 * 出现如下问题：thread-0------>thread-3--data
 */
public class ThreadLocalDemo2 {

    private static ThreadLocal<String> content = new ThreadLocal<>();


    public static void main(String[] args) {

        ThreadLocalDemo2 demo = new ThreadLocalDemo2();

        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                content.set(Thread.currentThread().getName() + "--data");
                System.out.println(Thread.currentThread().getName() + "------>" + content.get());
            }, "thread-" + i).start();
        }
    }
}
